export function arrayToTree(array, rootId = null) {
  let tree = [];
  let children = array.filter((item) => item.parentId === rootId);
  if (children.length === 0) {
    return null;
  }

  for (let child of children) {
    let grandChildren = arrayToTree(array, child.id);
    if (grandChildren) {
      child.children = grandChildren;
    }
    tree.push(child);
  }
  return tree;
}
